<template>
<div class="content-center">
  <div class="content-cotainer border-box">
    <div class="content-breadcrumb">
      <el-breadcrumb separator="/" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/' }">审计分析</el-breadcrumb-item>
        <el-breadcrumb-item>审计工作底稿</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="audit-content">
      <div class="centent-title">
        <span>{{title}}</span>
      </div>
      <!-- 页面内容 -->
      <div class="centent-inner" style="padding:15px;">

        <el-row :gutter="20" style="margin-top: 20px;">
          <el-form :model="form" label-width="120px" size="small">
            <el-row>
              <el-col :span="7">
                <el-form-item label="审计底稿名称：">
                  <el-input v-model="form.auditDraftNm" placeholder="请输入底稿名称" size="small"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="审计事项：">
                  <el-select v-model="form.auditItemDsc" placeholder="请选择审计事项" size="small">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="细分审计事项：">
                  <el-select v-model="form.auditItemDsc" placeholder="请选择细分审计事项" size="small">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <!--<el-button type="primary" icon="el-icon-search" size="small" style="margin-left:33px;" @click="findByParam">查询</el-button>-->
            </el-row>
            <el-row>
              <el-col :span="7">
                <el-form-item label="底稿状态：">
                  <el-select v-model="form.lcsCd" placeholder="请选择底稿状态" size="small">
                    <el-option v-for="item in lcsCdOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="证据名称：">
                  <el-input v-model="form.docNm" placeholder="请输入证据名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="编制人：">
                  <el-input v-model="form.rcrdCrtpsnNm" placeholder="请输入编制人"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="15">
                <el-form-item label="编制日期：">
                  <!--<el-date-picker v-model="form.rcrdCrtTm" style="width: 160px" placeholder="请选择编制日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" size="small"></el-date-picker>&#45;&#45;<el-date-picker v-model="form.rcrdCrtTm" style="width: 160px" placeholder="请选择编制日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" size="small"></el-date-picker>-->
                  <el-date-picker v-model="form.writeDt"  type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                  <el-button type="primary" icon="el-icon-search" size="small" style="margin-left:33px;" @click="findByParam()">查询</el-button>
                  <el-button type="primary" icon="el-icon-refresh-left" size="small" style="margin-left:33px;" @click="reset()">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-row>
        <el-row justify="space-around" type="flex">
          <el-col :span="24">
            <el-button type="primary" size="small" icon="el-icon-document-add" @click="newdraft">新建</el-button>
            <!--<el-button type="info" size="small" icon="el-icon-edit" @click="editdraft">修改</el-button>-->
            <el-button type="danger" size="small" icon="el-icon-delete" @click="deletedraft">废弃</el-button>
            <el-button type="primary" size="small" icon="el-icon-share">共享</el-button>
            <!--<el-button type="primary" size="small" icon="el-icon-s-promotion" @click="copydraft">复制</el-button>
            <el-button type="primary" size="small" icon="el-icon-edit">修订</el-button>-->
            <!--<el-button type="primary" size="small" icon="el-icon-edit-outline">录入问题汇总</el-button>-->
            <el-button type="primary" size="small" icon="el-icon-sort">同步审计底稿</el-button>
            <!--<el-button type="primary" size="small" icon="el-icon-search">查看审核意见</el-button>-->
            <el-button type="primary" size="small" icon="el-icon-tickets" @click="showDraftStatus">维护底稿状态</el-button>
            <!--<el-button type="primary" size="small" icon="el-icon-document" @click="showDraftAnnotate">批注</el-button>-->
          </el-col>
        </el-row>
        <el-row>
          <el-table :data="datalist" :row-class-name="tableRowClassName" @selection-change="selectedchange" stripe>
            <el-table-column type="selection" fixed width="50"></el-table-column>
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <!--<el-table-column label="审计底稿编号" prop="auditDraftId" align="center"></el-table-column>-->
            <el-table-column label="审计底稿名称" prop="auditDraftNm" align="center" width="200px">
              <template slot-scope="scope">
                <el-button type="text" @click="editdraft(scope.row.auditDraftId, scope.row.lcsCd)" >{{scope.row.auditDraftNm}}</el-button>
              </template>
            </el-table-column>
            <el-table-column label="审计事项" prop="auditItemDsc" align="center"></el-table-column>
            <el-table-column label="细分审计事项" prop="auditItemDsc" align="center" width="200px"></el-table-column>
            <el-table-column label="证据名称" prop="docNm" align="center" width="100px"></el-table-column>
            <el-table-column label="编制日期" prop="writeDt" align="center" width="200px"></el-table-column>
            <el-table-column label="编制人" prop="rcrdCrtpsnNm" align="center"></el-table-column>
            <el-table-column label="状态" prop="lcsCd" align="center" width="100px">
              <template slot-scope="scope">
                <el-button type="text" v-if="scope.row.lcsCd === '0'" @click="toDraftStatusDetail(scope.row.auditDraftId, scope.row.lcsCd)">编制中</el-button>
                <el-button type="text" v-else-if="scope.row.lcsCd === '1'" @click="toDraftStatusDetail(scope.row.auditDraftId, scope.row.lcsCd)">审核中</el-button>
                <el-button type="text" v-else-if="scope.row.lcsCd === '2'" @click="toDraftStatusDetail(scope.row.auditDraftId, scope.row.lcsCd)">审核通过</el-button>
                <el-button type="text" v-else-if="scope.row.lcsCd === '3'" @click="toDraftStatusDetail(scope.row.auditDraftId, scope.row.lcsCd)">审核不通过</el-button>
                <el-button type="text" v-else-if="scope.row.lcsCd === '4'" @click="toDraftStatusDetail(scope.row.auditDraftId, scope.row.lcsCd)">废弃</el-button>
              </template>
            </el-table-column>
            <el-table-column label="关联的审计证据" prop="relationEvd" align="center" width="200px"></el-table-column>
            <el-table-column label="关联的取证单" prop="relationDocket" align="center" width="200px"></el-table-column>
            <el-table-column label="维护状态" prop="auditStatusDsc" align="center" width="100px">
              <template slot-scope="scope">
                <span v-if="scope.row.auditStatusDsc === '1'">未阅</span>
                <span v-else-if="scope.row.auditStatusDsc === '2'">已阅</span>
                <span v-else-if="scope.row.auditStatusDsc === '3'">需修订</span>
                <span v-else-if="scope.row.auditStatusDsc === '4'">需重写</span>
                <span v-else-if="scope.row.auditStatusDsc === '5'">需修改</span>
                <span v-else-if="scope.row.auditStatusDsc === '5'">需修改</span>
                <span v-else>已同步</span>
              </template>
            </el-table-column>
            <!--<el-table-column label="审核状态" prop="checkstatus" align="center"></el-table-column>
            <el-table-column label="批注" prop="annotateDsc" align="center"></el-table-column>-->
          </el-table>
        </el-row>
        <el-pagination style="margin-top: 10px;" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="10" layout="total, sizes, prev, pager, next, jumper" :total="40">
        </el-pagination>
        <el-dialog :visible.sync="dialogPermissionVisible" title="维护底稿状态" width="40%" top="10vh">
          <el-form  :model="statusTemp"  label-width="100px">
            <el-form-item label="底稿状态"  >
              <el-select v-model="statusTemp.auditStatusDsc"  placeholder="请选择" style="width: 70%;">
                <el-option v-for="item in auditStatus" :key="item.value"
                           :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogPermissionVisible = false">取消</el-button>
            <el-button  type="primary" @click="updateAuditStatusDsc(statusTemp.auditStatusDsc)">保存</el-button>
          </div>
        </el-dialog>

        <el-dialog :visible.sync="dialogAnnotateDscVisible" title="修改批注" width="40%" top="10vh">
          <el-form  :model="annotateTemp"  label-width="100px">
            <el-form-item label="批注：">
              <el-input type="textarea" :rows="3" v-model="annotateTemp.annotateDsc" placeholder="请输入批注"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogAnnotateDscVisible = false">取消</el-button>
            <el-button  type="primary" @click="updateAuditAnnotateDsc()">保存</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</div>
</template>

<script>
    import evidenceservice from '@/api/auditoperationApi/evidenceservice'
    import axios from 'axios'
export default {
  components: {},
  data() {
    return {
      data1: [],
      data2: [],
      dialogPermissionVisible: false,
      dialogAnnotateDscVisible: false,
      annotateTemp:{
        annotateDsc: ''
      },
      statusTemp: {
        auditStatusDsc: ''
      },
      auditStatus: [
        {
          value: '1',
          label: '未阅'
        }, {
          value: '2',
          label: '已阅'
        }, {
          value: '3',
          label: '需修订'
        }, {
          value: '4',
          label: '需重写'
        }, {
          value: '5',
          label: '需修改'
        }, {
          value: '6',
          label: '已同步'
        }
      ],
      selectedlist: [], // 勾选数组
      lcsCdOptions: [{
        value: '4',
        label: '废弃'
      }, {
        value: '3',
        label: '审核不通过'
      }, {
        value: '2',
        label: '审核通过'
      }, {
        value: '1',
        label: '审核中'
      }, {
        value: '0',
        label: '编制中'
      }],
      options: [{
        value: '1',
        label: '事项1'
      }, {
        value: '2',
        label: '事项2'
      }, {
        value: '3',
        label: '事项3'
      }],
      title: '底稿列表',
      currentPage: 1,
      data: [{
        b: '测试数据'
      }],
      model: {
        event: ''
      },
      datalist: [],
      flag: false,
      form: {
          auditDraftId: '',
          auditDraftNm: '',
          auditItemDsc: '',
          rcrdCrtpsnNm: '',
          writeDt: '',
          auditProcDsc: '',
          deterfactsDsc: '',
          remark: ''
      },
      newDraftForm: {
        show: false,
        title: '新建底稿'
      }
    }
  },
  computed: {

  },
  mounted() {
    this.getData()
  },
  methods: {
    handleDragStart(node, ev) {
        console.log('drag start', node);
      },
      handleDragEnter(draggingNode, dropNode, ev) {
        console.log('tree drag enter: ', dropNode.label);
      },
      handleDragLeave(draggingNode, dropNode, ev) {
        console.log('tree drag leave: ', dropNode.label);
      },
      handleDragOver(draggingNode, dropNode, ev) {
        console.log('tree drag over: ', dropNode.label);
      },
      handleDragEnd(draggingNode, dropNode, dropType, ev) {
        console.log('tree drag end: ', dropNode && dropNode.label, dropType);
      },
      handleDrop(draggingNode, dropNode, dropType, ev) {
        console.log('tree drop: ', dropNode.label, dropType);
      },
    reset(){
      this.form = {}
      this.getData ()
    },
    getData () {
      let params = {}
      axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/findWorkDraftList', params)
              .then(response => {
                //resolve(response);
                this.datalist = response.data.obj;
              }, err => {
                //reject(err);
              })
              .catch((error) => {
                //reject(error)
              })
    },

    findByParam () {
        debugger
      let params = this.form
      if(params.writeDt){
          params.beforeDate = evidenceservice.formatDate(params.writeDt[0],'yyyy-MM-dd hh:mm')
          params.afterDate = evidenceservice.formatDate(params.writeDt[1],'yyyy-MM-dd hh:mm')
          params.writeDt = ''
      }
      axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/findWorkDraftList', params)
              .then(response => {
                this.datalist = response.data.obj;
              }, err => {
                //reject(err);
              })
              .catch((error) => {
                //reject(error)
              })
    },

    deletedraft(){
      let ids= this.selectedlist.map(item => item.auditDraftId).join()
      let param = {};
      param.ids = ids ;
      param.lcsCd = '4' ;
      if(ids.length > 0){
        this.$confirm('此操作将废弃该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/updateWorkDraftParam', param)
                  .then(response => {
                    this.$message({
                      type: 'success',
                      message: '维护成功'
                    });
                    this.getData();
                  }, err => {
                  })
                  .catch((error) => {
                  })
        }).catch(action => {
        });
      }else{
        this.$message({
          type: 'info',
          message: '请选择记录'
        });
      }
    },
    toDraftStatusDetail(auditDraftId,lcsCd){
      this.$router.push({
        name: 'auditDraftStatusDetail', query: {auditDraftId: auditDraftId,type:'edit'}
      })
    },

    updateAuditStatusDsc(val){
      let ids= this.selectedlist.map(item => item.auditDraftId).join();
      let param = this.statusTemp;
      param.ids = ids ;
      axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/updateWorkDraftParam', param)
              .then(response => {
                this.$message({
                  type: 'success',
                  message: response.data.obj
                });
                this.dialogPermissionVisible = false
                this.getData();
              }, err => {
              }).catch((error) => {
      })
    },

    updateAuditAnnotateDsc(){
      let ids= this.selectedlist.map(item => item.auditDraftId).join();
      let param = this.annotateTemp;
      param.ids = ids ;
      axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/updateWorkDraftParam', param)
              .then(response => {
                this.$message({
                  type: 'success',
                  message: response.data.obj
                });
                this.dialogAnnotateDscVisible = false
                this.getData();
              }, err => {
              }).catch((error) => {
      })
    },


    showDraftStatus(){
      let ids= this.selectedlist
      if(ids.length > 0){
        this.dialogPermissionVisible = true
      }else{
        this.$message.warning('请勾选一行数据')
      }
    },

    showDraftAnnotate(){
      let ids= this.selectedlist
      if(ids.length > 0){
        this.dialogAnnotateDscVisible = true
      }else{
        this.$message.warning('请勾选一行数据')
      }
    },

    // 行索引
    tableRowClassName ({ row, rowIndex }) {
      row.index = rowIndex
    },
    selectedchange (val) {
      this.selectedlist = val
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    // 保存
    save() {
      this.newDraftForm.show = false
    },
    // 新建底稿
    newdraft() {
      this.$router.push({
        name: 'auditdraftadd'
      })
    },
    // 修改底稿
    editdraft(auditDraftId,lcsCd) {
      if(lcsCd == '2'){
        this.$router.push({
          name: 'auditDraftCheck', query: {auditDraftId: auditDraftId,type:'edit'}
        })
      }else{
        this.$router.push({
          name: 'auditDraftUpdate', query: {auditDraftId: auditDraftId,type:'edit'}
        })
      }
      /*if (this.selectedlist && Array.isArray(this.selectedlist) && this.selectedlist.length >=0) {
        // 没有勾选行
        if (this.selectedlist.length === 0) {
          this.$message.warning('请勾选一行数据')
        // 勾选一行
        } else if (this.selectedlist.length === 1) {
          this.$router.push({
            name: 'auditdraftadd', query: {auditDraftId: this.selectedlist[0].auditDraftId,type:'edit'}
          })
        // 勾选多行
        } else if (this.selectedlist.length > 1) {
          this.$message.warning('修改时只能勾选一行')
        }
      }*/
    },

      copydraft() {
          if (this.selectedlist && Array.isArray(this.selectedlist) && this.selectedlist.length >=0) {
              // 没有勾选行
              if (this.selectedlist.length === 0) {
                  this.$message.warning('请勾选一行数据')
                  // 勾选一行
              } else if (this.selectedlist.length === 1) {
                  this.$router.push({
                      name: 'auditdraftadd', query: {auditDraftId: this.selectedlist[0].auditDraftId,type:'copy'}
                  })
                  // 勾选多行
              } else if (this.selectedlist.length > 1) {
                  this.$message.warning('复制时只能勾选一行')
              }
          }
      },
    // 删除底稿
    /*deletedraft () {
      console.log(this.selectedlist)
      if (this.selectedlist && Array.isArray(this.selectedlist) && this.selectedlist.length >=0) {
        // 没有勾选行
        if (this.selectedlist.length === 0) {
          this.$message.warning('请至少勾选一行')
        // 勾选一行或多行
        } else if (this.selectedlist.length > 0) {
          this.selectedlist.forEach(element => {
                this.datalist.splice(element.index, 1, {deleteflag: 1})
            })
          let templist = []
          this.datalist.forEach(item => {
            if (!item.deleteflag) {
              templist.push(item)
            }
          })
          this.datalist = templist
        }
      }
    },*/
    // 复制
    /*copydraft () {
      console.log(this.selectedlist)
      if (this.selectedlist && Array.isArray(this.selectedlist) && this.selectedlist.length >=0) {
        // 没有勾选行
        if (this.selectedlist.length === 0) {
          this.$message.warning('请勾选一行')
        // 勾选一行或多行
        } else if (this.selectedlist.length === 1) {
          this.datalist.push({
            id: this.selectedlist[0].id,
            a: this.selectedlist[0].a,
            b: this.selectedlist[0].b,
            c: this.selectedlist[0].c,
            d: this.selectedlist[0].d,
            e: this.selectedlist[0].e,
            f: this.selectedlist[0].f
          })
        } else if (this.selectedlist.length > 1) {
          this.$message.warning('一次只能复制一行')
        }
      }
    }*/
  }
}
</script>

<style lang="less" scoped>
.content-cotainer {
  padding: 0 20px 20px 20px;
  height: 100%;
}
</style>
